<?php

class BigBrother extends AbstractSingleton  {

    /**
     * @return BigBrother
     */
    public static function getInstance() { return parent::doGetInstance(get_class()); }

    public function watchForUser() {
        $this->detectLjUser();
    }

    private function detectLjUser() {
        if (!empty($_SERVER['HTTP_REFERER']) &&
            preg_match("~http://([^.]+)\.livejournal\.com/friends~", $_SERVER['HTTP_REFERER'], $matches)
        ) {
            Cookies::set('ljUser', $matches[1], 700);
        }
    }

    public function isRobot() {
        return preg_match('/Rambler|Yandex|Google/i', $_SERVER['HTTP_USER_AGENT']);
    }

    public function getLjUsername() {
        return Cookies::get('ljUser');
    }

//    public static function getUserId() {
//        if (!$userId = Cookies::get(self::COUNTER_COOKIE_NAME)) {
//            $userId = mt_rand(0, 1000000000);
//            Cookies::set(self::COUNTER_COOKIE_NAME,$userId,700);
//        }
//        return md5($userId); // safe for hacks
//    }
}


?>